package com.bitBusy.manageyourriches.utilityClasses.dialogboxes;


import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v4.app.DialogFragment;

public class BasicDialogBox extends DialogFragment implements DialogBox{

	protected AlertDialog.Builder builder;
	protected Context currActivity;
	protected String title;
	protected String message;
	protected String positiveText;
	protected String negativeText;
	protected String neutralText;
	protected DialogInterface.OnClickListener positiveListener;
	protected DialogInterface.OnClickListener negativeListener;
	protected DialogInterface.OnClickListener neutralListener;
	private AlertDialog myDialog;

	
	public void set(Context the_context, String the_title, String the_message, 
			String the_positiveText, DialogInterface.OnClickListener the_positiveListener,
			String the_negativeText, DialogInterface.OnClickListener the_negativeListener,
			String the_neutralText, DialogInterface.OnClickListener the_neutralListener)
	{
		if (the_context != null)
		{
			currActivity = the_context;
			builder = new AlertDialog.Builder(currActivity);
			message = the_message;
			title = the_title;
			positiveText = the_positiveText;
			positiveListener = the_positiveListener;
			negativeText = the_negativeText;
			negativeListener = the_negativeListener;
			neutralText = the_neutralText;
			neutralListener = the_neutralListener;
		}
		else
		{
			throw new NullPointerException("Context is null at DialogBox building!");

		}
	
	}
	private void buildDialog() {
			setTitle();
			setMessage();
			setPositive();
			setNegative();
			setNeutral();
			createDialog();
			//showDialog();
	}

	private void setTitle()
	{
		builder.setTitle(title);
	}
	private void setMessage()
	{
		builder.setMessage(message);
	}
	private void setPositive()
	{
		if (positiveListener != null)
		{
			builder.setPositiveButton(positiveText, positiveListener);
		}
		else
		{
			throw new NullPointerException("Positive Listener is null");
		}
	}
	private void setNegative()

	{
		if (negativeListener != null)
		{
			builder.setNegativeButton(negativeText, negativeListener);
		}
	/*	else
		{
			throw new NullPointerException("Negative Listener is null");
		}
		*/
	}
	private void setNeutral()

	{
		if (neutralListener != null)
		{
			builder.setNeutralButton(neutralText, neutralListener);
		}
	/*	else
		{
			throw new NullPointerException("Neutral Listener is null");
		}
		*/
	}
	private void createDialog()
	{
		builder.create();
	}
	@Override
	public void showDialog() {
					if (builder != null)
					{
						buildDialog();
						myDialog = builder.show();
					}	
	}
	

	/**
	 * cancel 
	 */
	public void cancel()
	{
		if (myDialog != null)
		{
			myDialog.dismiss();
		}
	}
	
}
